package com.rw.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ViewSController {


    @RequestMapping("v1")
    public View getView(){
        View view = new InternalResourceView("/view.jsp");
        System.out.println("ViewSController.getView执行了");
        return view;
    }

    @RequestMapping("v2")
    public View getView2(HttpServletRequest request){
        View view = new RedirectView(request.getContextPath()+"/redirect.jsp");
        System.out.println("ViewSController.getView2执行了重定向");
        return view;
    }

    @RequestMapping("gm")
    public ModelAndView getModelAndView(){
        ModelAndView modelAndView =new ModelAndView();
        modelAndView.setViewName("redirect.jsp");
        modelAndView.addObject("msg","我的是modelandview设置的值");
        return modelAndView;
    }

    @RequestMapping("tmp")
    public String getModelAndViewToTmp(){
        System.out.println("ViewSController.getModelAndViewToTmp执行了");
        return "/a/b/c/tmp.jsp";
    }

    @RequestMapping("tmp2")
    public String getStringView(){
        return "tmp";
    }
}
